package cn.gson.work.controller;

import cn.gson.work.model.pojos.Dept;
import cn.gson.work.model.pojos.Volumelibrary;
import cn.gson.work.model.service.DeptService;
import cn.gson.work.model.service.VolumelibraryService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class VolumelibraryController {
    @Autowired
    VolumelibraryService vls;

    /**
     * 分页条件模糊查询
     * @param page
     * @param size
     * @param search
     * @return
     */
    @RequestMapping("/findVolume")
    @ResponseBody
    public Map<String, Object> findVolume(@RequestParam("page") Integer page,
                                        @RequestParam("size") Integer size,
                                        @RequestParam("search") String search){
        System.out.println(page+"======================================="+size);
        Page<Object> obj= PageHelper.startPage(page, size);
        vls.findVolume(search);
        Map<String,Object> map =new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",obj.getResult());
        return map;
    }

    /**
     * 查询卷库数据,案卷添加时调用（未数据重复校验）
     * @return
     */
    @RequestMapping("/findVolumeAll")
    @ResponseBody
    public List<Volumelibrary> findVolumeAll(){
        return vls.findVolumeAll();
    }

    /**
     * 卷库添加
     * @param vl
     */
    @RequestMapping("/addVolume")
    @ResponseBody
    public void addVolume(@RequestBody Volumelibrary vl){
        vls.addVolume(vl);
    }
}
